;$(function () {
    // 初始化
    getInfo();
    if (status == 1) {
        // 未通过
        $('.btn-group').hide();
        $('.status-tip').show().html('审批状态<span class="btn-red">拒绝</span>');
    }
    if (status == 2) {
        // 通过
        $('.btn-group').hide();
        $('.status-tip').show().html('审批状态<span class="btn-blue">通过</span>');
    }
});

/**
 * 功能：初始化页面数据
 * */
function getInfo() {
    $.ajax({
        url: '/loginFree/xzCustomerOrderBackMoneyDetail',
        type: 'POST',
        dataType: "json",
        data: {
            orderBackMoneyId,
            productOrderId,
        },
        success: function (data) {
            if (data.code == "000000") {
                var infoData = data.data;
                var productData = infoData.customerOrderBackMoney;

                // 基本信息
                $('#infoNumber').html(infoData.order.orderNumber || '-');
                $('#infoContractNumber').html(infoData.order.contractNumber || '-');
                var infoStatus;
                switch (infoData.order.orderStatus) {
                    case '1':
                        infoStatus = '等待回款';
                        break;
                    case '2':
                        infoStatus = '已完成';
                        break;
                    case '3':
                        infoStatus = '作废';
                        break;
                    case '4':
                        infoStatus = '部分回款';
                        break;
                }
                $('#infoStatus').html(infoStatus || '-');
                $('#infoCustomerName').html(infoData.order.customerName || '-');
                $('#infoOwner').html(infoData.order.userName || '-');
                $('#infoCompany').html(infoData.order.companyName || '-');
                $('#infoCreateTime').html(infoData.order.createTm || '-');
                $('#customerNumber').html(productData[0].customerNumber || '-');
                if (infoData.order.refundType == 0) {
                    $('#refundType').html('订单产品');
                }
                if (infoData.order.refundType == 1) {
                    $('#refundType').html('余额');
                }
                $('#royaltyStatus').html(infoData.royaltyStatus || '-')
                // 产品明细
                var productDom = '';
                for (let i = 0; i < productData.length; i++) {
                    productDom += '<div class="product-list">';
                    productDom += '<h5>产品名称：<span>' + productData[i].productName + '</span></h5>';
                    productDom += '<ul><li><span>' + priceJudgment(productData[i].productOriginalPrice) + '</span>产品原价</li>';
                    productDom += '<li><span>' + priceJudgment(productData[i].productMemberPrice) + '</span>会员价</li>';
                    productDom += '<li><span>' + priceJudgment(productData[i].productFinalPrice) + '</span>产品成交价</li></ul></div>';
                }
                $('#productBox').html(productDom);
                $('#applyBackMoney').html(productData[0].applyBackMoney || '-');
                $('#serviceMoney').html(productData[0].serviceMoney || '-');
                $('#backMoney').html(productData[0].backMoney || '-');

                // 退款备注
                $('#remarks').html(infoData.sqbz);
            } else {
                $.alert("操作失败");
            }
        },
        error: function () {
            $.alert("失败");
        }
    });
}

/**
 * 功能：价格字段值判断
 * */
function priceJudgment(price) {
    switch (price) {
        case null:
            return '-';
            break;
        case undefined:
            return '-';
            break;
        default:
            return price;
    }
}

function examine(type) {
    if (type == 1) {
        var title = '拒绝';
        var content = '您确认要拒绝退款申请吗？';
        var btnClass = 'btn-red';
    } else {
        var title = '通过';
        var content = '您确认要通过退款申请吗？';
        var btnClass = 'btn-blue';
    }
    $.alert({
        title: title + '提醒',
        content,
        buttons: {
            confirm: {
                text: title,
                btnClass,
                action: function () {
                    var jsonData = {
                        orderBackMoneyId,
                        adoptSituation: 2,
                        backStatus: type, // 审核事件：1-未通过 2-通过
                    }
                    console.log('参数：', jsonData);
                    $.ajax({
                        url: '/loginFree/xzOrderRefundFinance',
                        type: 'POST',
                        contentType: "application/json;charset=utf-8",
                        data:JSON.stringify(jsonData),
                        success: function(data) {
                            if (data.code == '000000') {
                                $.alert({
                                    title: '系统提醒',
                                    content: type == 1 ? '退款申请已拒绝！' : '退款申请已通过！',
                                });
                                $('.btn-group').hide();
                                $('.status-tip').show().html('审批状态<span class="' + btnClass + '">' + title + '</span>');
                            } else {
                            }
                        },
                        error: function() {

                        }
                    });
                }
            },
            cancel: {
                text: '取消'
            }
        }
    });
}




















